#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QTextEdit>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QScrollArea>
#include <QTimer>
#include <QListWidget>
#include <QListWidgetItem>

class ChatBubble : public QWidget
{
    Q_OBJECT

public:
    ChatBubble(const QString &message, bool isOwnMessage, QWidget *parent = nullptr);
    void setMessage(const QString &message);
    QString getMessage() const;

private:
    QLabel *messageLabel;
    QString messageText;
    bool isOwn;
};

class ChatWidget : public QWidget
{
    Q_OBJECT

public:
    ChatWidget(const QString &userName, const QString &avatarColor, QWidget *parent = nullptr);
    void addMessage(const QString &message, bool isOwnMessage);
    void showTypingIndicator(bool show);

signals:
    void messageSent(const QString &message);

private slots:
    void onSendButtonClicked();
    void onInputTextChanged();

private:
    QVBoxLayout *mainLayout;
    QHBoxLayout *headerLayout;
    QLabel *avatarLabel;
    QLabel *userNameLabel;
    QListWidget *messageList;
    QHBoxLayout *inputLayout;
    QLineEdit *inputEdit;
    QPushButton *sendButton;
    QLabel *typingIndicator;
    QTimer *typingTimer;
    QString userName;
    QString avatarColor;
};

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private slots:
    void onLeftMessageSent(const QString &message);
    void onRightMessageSent(const QString &message);

private:
    QHBoxLayout *mainLayout;
    ChatWidget *leftChat;
    ChatWidget *rightChat;
};

#endif // WIDGET_H
